package com.yc.d0415;

public class 并发与同步 {
    static int i = 0;

    public static void main(String[] args) throws InterruptedException {
        for (int j = 0; j < 100 ; j++) {
            Thread t = new Thread(()->{
                for (int k = 0; k < 1000 ; k++) {
                    //同步关键字,同时只能有一个线程执行
                    synchronized (并发与同步.class){
                        //i++ 不是原子操作
                        i++;
                    }
                }
            });
            t.start();
        }
        Thread.sleep(20);
        System.out.println("i = " + i);
    }
}
